import React, { Component } from "react";
import { Select } from "antd";
import { getChannels } from "../../api/channel";
//封装频道组件
export default class Channel extends Component {
  state = {
    channel: [],
  };
  render() {
    console.log(this.props);
    return (
      <Select
        placeholder="请选择频道"
        style={{
          width: 200,
        }}
        defaultValue={this.props.value}
        onChange={this.props.onChange()}
        options={this.state.channel.map((item) => ({
          value: item.id,
          label: item.name,
        }))}
      />
    );
  }
  async componentDidMount() {
    this.getChannelList();
  }
  async getChannelList() {
    const res = await getChannels();
    this.setState({
      channel: res.data.channels,
    });
  }
}
